package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.MangerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
public class SkuMangeController {

    @Autowired
    MangerService mangerService;
    // /admin/product/saveSkuInfo
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        this.mangerService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    // /admin/product/list/{page}/{limit}
    @GetMapping("/list/{page}/{limit}")
    public Result SkuInfolist(@PathVariable Long page,
                              @PathVariable Long limit,
                              SkuInfo skuInfo){
        Page<SkuInfo> skuInfoIPage = new Page<>(page,limit);
        IPage<SkuInfo> page1 = this.mangerService.SkuInfolist(skuInfoIPage,skuInfo);
        return Result.ok(page1);
    }

    // /admin/product/onSale/{skuId} 上架
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        this.mangerService.onSale(skuId);
        return Result.ok();
    }
    // /admin/product/cancelSale/{skuId}
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        this.mangerService.cancelSale(skuId);
        return Result.ok();
    }

}
